package net.mihome.app.bean;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.mihome.app.bean.net.ResponsePojo;

/**
 * 文章。
 * 很多内容比如办证、帮助等都可以做为文章来存在。
 * 特点是图片存在于内容里边是html结构
 * */
public class Article {
	public final static int ARTICLE_TYPE_BANZHENG=100;
	private int id;
	private String title;
	private String subTitle; 
	private String subDate;
	private String content;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getSubTitle() {
		return subTitle;
	}
	public void setSubTitle(String subTitle) {
		this.subTitle = subTitle;
	}
	public String getSubDate() {
		return subDate;
	}
	public void setSubDate(String subDate) {
		this.subDate = subDate;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public static Article parse(ResponsePojo responsePojo){
		Map map=(Map) responsePojo.getData();
		return parse(map);
	}
	public static Article parse(Map map){
		Article article=new Article();
		Double idDouble=(Double) map.get("id");
		article.setId(idDouble.intValue());
		article.setTitle((String) map.get("title"));
		article.setSubDate((String) map.get("create_at"));
		article.setSubTitle((String) map.get("subtitle"));
		article.setContent((String) map.get("content"));
		return article;
	}
	public static List<Article> parseList(ResponsePojo responsePojo){
		List<Article> arList=new ArrayList<Article>();
		List list=(List) responsePojo.getData();
		if(list!=null&&!list.isEmpty()){
			Iterator iterator=list.iterator();
			while(iterator.hasNext()){
				Map map=(Map) iterator.next();
				Article article=Article.parse(map);
				arList.add(article);
			}
		}
        return arList;   
	}
}
